package com.yonyougov.devops.cruxcisupport.appenv;

import com.yonyougov.devops.cruxcisupport.appenv.dto.AppEnvPageDbParams;
import com.yonyougov.devops.cruxcisupport.appenv.dto.AppEnvPageLikeDbParams;
import com.yonyougov.devops.cruxcisupport.appenv.vo.AppEnvPageLikeReqVo;
import com.yonyougov.devops.cruxcisupport.appenv.vo.AppEnvPageLikeRespVo;
import com.yonyougov.devops.cruxcisupport.appenv.vo.AppEnvPageVo;
import com.yonyougov.devops.cruxcisupport.appenv.vo.AppEnvVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;

/**
 * t_app_env数据层实现
 */
@Repository
public class AppEnvDaoImpl extends BaseDaoImpl<AppEnvEntity, BigInteger> implements AppEnvDao {
    private final SqlSessionTemplate sqlSessionTemplate;

    public AppEnvDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public List<AppEnvPageVo> findAllJoinBy(AppEnvPageLikeDbParams appEnvEntityVo) {
        String statement = AppEnvEntity.class.getName() + "Mapper.findAllJoinBy";
        return sqlSessionTemplate.selectList(statement, appEnvEntityVo);
    }

    @Override
    public int countByJoin(AppEnvPageLikeDbParams appEnvEntityVo) {
        String statement = AppEnvEntity.class.getName() + "Mapper.countByJoin";
        return sqlSessionTemplate.selectOne(statement, appEnvEntityVo);
    }

    @Override
    public List<AppEnvPageLikeRespVo> findPageLike(AppEnvPageLikeReqVo appEnvPageLikeReqVo) {
        String statement = AppEnvEntity.class.getName() + "Mapper.findPageLike";
        return sqlSessionTemplate.selectList(statement, appEnvPageLikeReqVo);
    }

    @Override
    public int countByPageLike(AppEnvPageLikeReqVo appEnvPageLikeReqVo) {
        String statement = AppEnvEntity.class.getName() + "Mapper.countByPageLike";
        return sqlSessionTemplate.selectOne(statement, appEnvPageLikeReqVo);
    }

    @Override
    public List<AppEnvPageVo> findAppEnvPageBy(AppEnvPageDbParams dbParams) {
        String statement = AppEnvEntity.class.getName() + "Mapper.findAppEnvPageBy";
        return sqlSessionTemplate.selectList(statement, dbParams);
    }

    @Override
    public int countByAppEnvPage(AppEnvPageDbParams dbParams) {
        String statement = AppEnvEntity.class.getName() + "Mapper.countByAppEnvPage";
        return sqlSessionTemplate.selectOne(statement, dbParams);
    }

    @Override
    public AppEnvVo findByEnvNameAndAppName(String envName, String appName) {
        String statement = AppEnvEntity.class.getName() + "Mapper.findByEnvNameAndAppName";
        HashMap<Object, Object> map = new HashMap<>();
        map.put("envName", envName);
        map.put("appName", appName);
        return sqlSessionTemplate.selectOne(statement, map);
    }

    @Override
    public void batchDeleteById(List<BigInteger> ids) {
        String statement = AppEnvEntity.class.getName() + "Mapper.batchDeleteById";
        HashMap<Object, Object> map = new HashMap<>();
        map.put("ids", ids);
        sqlSessionTemplate.delete(statement, map);
    }

    @Override
    public List<AppEnvEntity> findById(List<BigInteger> ids) {
        String statement = AppEnvEntity.class.getName() + "Mapper.findById";
        HashMap<Object, Object> map = new HashMap<>();
        map.put("ids", ids);
        return sqlSessionTemplate.selectList(statement, map);
    }
}
